{extend name='common/common' /}

{block name="style"}
<style type="text/css">
    .container-fluid .btn.btn-sm{
        float: right;
        margin-left: 10px;
    }
    .container-fluid{
        padding-right: 0px;
    }
    .layui-form-item{
        margin-bottom: 0px;
    }
    .layui-form-item .layui-inline{
        margin-right: 0px;
    }
    .king{
        margin-right: 10px;
    }
    .layui-form{
        display: inline-block;
    }
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>客户列表</h5>
        </div>
        <div class="ibox-content">
            <!--<div class="form-group clearfix col-sm-1">-->
                <!--{if authCheck('articles/articleadd')}-->
                <!--<a href="{:url('articles/articleadd')}"><button class="btn btn-outline btn-primary" type="button">添加会员</button></a>-->
                <!--{/if}-->
            <!--</div>-->
            <!--   删除   -->
            <div class="container-fluid form-inline pull-right" style="margin-top: 10px">
                <button class="btn btn-danger btn-sm getIDs" data-delete="{:url('member/deleteList')}" data-param="">删除会员</button>
            </div>
			<?php if(authCheck('member/director')):?>
				<div class="container-fluid form-inline pull-right" style="margin-top: 10px">
                	<button class="btn btn-danger btn-sm getIDs" data-release="{:url('member/releaseMem')}" data-param="">强制释放</button>
            	</div>
			<?php endif;?>
            <!--搜索框开始 pull-right-->

            {if(authCheck('member/memberlist'))}
            <!--  用户本人的客户列表  -->
            <form id='commentForm' data-url="{:url('Member/memberList')}" role="form" method="post" class="form-inline pull-left">
                <div class="content clearfix m-b">

                    <?php if(authCheck('member/director')):?>
                        <div class="form-group">
                            <label>部门：</label>
                            <input type="text" class="form-control" id="depart" name="depart" readonly placeholder="请选择部门">
                            <input type="hidden" class="form-control" id="depart_id" name="depart_id" readonly>
                        </div>
                        <div class="form-group">
                            <label>咨询师姓名：</label>
                            <input type="text" class="form-control" id="staff" name="staff">
                        </div>
                    <?php elseif(authCheck('member/executive_director')):?>
                        <div class="form-group">
                            <label>咨询师姓名：</label>
                            <input type="text" class="form-control" id="staff" name="staff">
                        </div>
                    <?php endif;?>

                    <div class="form-group">
                        <label>客户姓名：</label>
                        <input type="text" class="form-control" id="name" name="name">
                    </div>
                    <div class="form-group">
                        <label>联系方式：</label>
                        <input type="text" class="form-control" id="phone" name="phone">
                    </div>
                    <!-- 新增时间  -->
                    <div class="form-group">
                        <label>日期范围：</label>
                        <div class="layui-form">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="KL-time" id="KL-time" placeholder="开始 到 结束">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>等级：</label>
                        <select class="form-control"  name="grade" id="grade">
                            <option value="0">请选择</option>
                            <?php foreach($gradeArr as $val): ?>
                            <option value="<?=$val['id']?>"><?=$val['name']?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>状态：</label>
                        <select class="form-control" name="status" id="status">
                            <option value="0">请选择</option>
                            <?php foreach($statusArr as $val): ?>
                            <option value="<?=$val['id']?>"><?=$val['name']?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            {/if}
            <!--  主管客户列表  -->
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th>checkbox</th>
                        <th class="text-center" data-field="id">会员ID</th>
                        <th class="text-center" data-field="name">姓名</th>
                        <th class="text-center" data-field="phone">联系电话</th>
                        <th class="text-center" data-field="adress">地址</th>
                        <th class="text-center" data-field="qq">QQ</th>
                        <th class="text-center" data-field="weixin">微信</th>
                        <th class="text-center" data-field="gradeN">等级</th>
                        <th class="text-center" data-field="statusN">状态</th>
                        <th class="text-center" data-field="relation">所属咨询师</th>
                        <th class="text-center" data-field="time">加入时间</th>
                        <th class="text-center" data-field="remarks">备注</th>
                        <?php if(authCheck('member/memberlist')): ?>
                        <th class="text-center" data-field="operate">操作</th>
                        <?php endif;?>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
<div class="laycontent" style="display: none;width: 300px;padding: 30px 15px;">
    <ul id="tree"></ul>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function initTable() {
        var url = $("#commentForm").attr('data-url');
//        alert(url);
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: url, //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            columns : [{
                checkbox: true,
                formatter:function(value,row,index){
                    if (row.state == true){
                        return {
                            checked : value,//设置选中
                        };
                    }
                    return value;
                },
            }],
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    name:$('#name').val(),
                    phone:$('#phone').val(),
                    grade:$('#grade').val(),
                    status:$('#status').val(),
                    time:$('#KL-time').val(),
                    staff:$('#staff').val(),//咨询师名字
                    depart_id:$('#depart_id').val(),//部门id
                };
                return param;
            },
            onLoadSuccess: function(res){ //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

        $('.getIDs').on('click',function(){
            var checkedOn= $('#cusTable').bootstrapTable('getSelections');
            var IDs = '';
            for(var i=0;i<checkedOn.length;i++){
                if(i == 0){
                    IDs = checkedOn[0].id;
                }else{
                    IDs += ',' + checkedOn[i].id;
                }
            }
            $('.getIDs').attr('data-param',IDs);
        })
    });

    //时间选择
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#KL-time'
            ,range: true
        });
    })
	function releasemem(id) {
        $('.getIDs').attr('data-param',id);
		var param = JSON.stringify($('.getIDs').attr("data-param").split(","));
		$.post("{:url('member/releaseMem')}",{param:param},function(data){
			if(data.code == 1){
				layer.msg(data.msg,{time : 1000},function(){
					layer.closeAll();
					initTable();
				});
			}else{
				layer.msg('释放失败',{time : 1000},function(){
					layer.closeAll();
					return false;
				});
			}
		})
    }
</script>
<script>
    $(function(){
        getTree();
        layui.use(['form'], function(){
            var form = layui.form;
        });

        $('#depart').on('click',function(){
            selectSchoolBox = layer.open({
                type: 1,
                title: '请选择部门',
                anim: 2,
                skin: 'layui-layer-molv', //加上边框
                area: ['300px', '350px'], //宽高
                content: $(".laycontent")
            });
        });
    });
    function getTree(){
        layui.use(['tree', 'layer'], function(){
            var layer = layui.layer;

            $.getJSON("{:url('Department/index')}", function(res){
                console.log(res);
                if(111 == res.code){
                    window.location.reload();
                }
                layui.tree({
                    elem: '#tree'
                    ,nodes: res.data
                    ,click: function(node){
                        $('#depart').val(node.name);
                        $('#depart_id').val(node.id);
                        layer.closeAll();
                    }
                });
            });
        });
    }
</script>
{/block}
